import logging

import sentry_sdk

from condition import Condition
from finite_state_machine import FiniteStateMachine
from state import State
from transition import Transition

sentry_sdk.init(
    dsn="https://d91c2452b4dc584a3894433488b3e701@o4506470646087680.ingest.sentry.io/4506471005683712",
    traces_sample_rate=1.0,
    profiles_sample_rate=1.0,
)
logger = logging.getLogger('fsm')

if __name__ == '__main__':
    fsm = FiniteStateMachine()
    condition_a_gt_10 = Condition('number', 'int', ('a', '>', 2000), fsm)
    condition_a_lt_20 = Condition('number', 'int', ('a', '<', 1000), fsm)
    transition_a_to_b = Transition('a_to_b', 'a', 'b', [condition_a_gt_10])
    transition_b_to_a = Transition('b_to_a', 'b', 'a', [condition_a_lt_20])


    class StateA(State):
        def on_enter(self):
            logger.info(self.machine.global_parameters['a'])
            logger.info('a enter')

        def on_exit(self):
            logger.info(self.machine.global_parameters['a'])
            logger.info('a exit')

        def on_process(self, delta):
            self.machine.global_parameters['a'] += 1


    class StateB(State):
        def on_enter(self):
            logger.info(self.machine.global_parameters['a'])
            logger.info('b enter')

        def on_exit(self):
            logger.info(self.machine.global_parameters['a'])
            logger.info('b exit')

        def on_process(self, delta):
            self.machine.global_parameters['a'] -= 1


    state_a = StateA('a', fsm, [transition_a_to_b])
    state_b = StateB('b', fsm, [transition_b_to_a])

    fsm.add_states([state_a, state_b])
    fsm.current_state = state_a
    fsm.initial_state = state_a
    fsm.set_parameter('a', 1000)
    fsm.start()
